package org.example.simplemanagementsystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.simplemanagementsystem.mapper.ClazzMapper;
import org.example.simplemanagementsystem.pojo.Clazz;
import org.example.simplemanagementsystem.pojo.ClazzQueryParam;
import org.example.simplemanagementsystem.pojo.Emp;
import org.example.simplemanagementsystem.pojo.PageResult;
import org.example.simplemanagementsystem.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public PageResult page(ClazzQueryParam clazzQueryParam) {
        PageHelper.startPage(clazzQueryParam.getPage(), clazzQueryParam.getPageSize());

        List<Clazz> empList = clazzMapper.list(clazzQueryParam);

        Page<Clazz> p = (Page<Clazz>) empList;

        return new PageResult(p.getTotal(), p.getResult());
    }

    @Override
    public void delete(Long id) {
        clazzMapper.delete(id);
    }

    @Override
    public void add(Clazz clazz) {
        clazzMapper.add(clazz);
    }

    @Override
    public Clazz getClassById(Long id) {
        return clazzMapper.getClassById(id);
    }

    @Override
    public void update(Clazz clazz) {
        clazzMapper.update(clazz);
    }

    @Override
    public List<Clazz> findAll() {
        return clazzMapper.findAll();
    }
}
